/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bl;

import Config.Localization;
import da.DACustomer;
import entities.Customer;
import entities.User;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;

/**
 *
 * @author Bich Tran Van
 */
public class BLCustomer {

    private DACustomer daCustomer = null;
    public BLCustomer(){
        daCustomer = new DACustomer();
    }
    public ArrayList<Customer> getAll(User user) {
        return daCustomer.getAll(user);
    }
    
    public ArrayList<Customer> getByID(int id, User user) {
        return daCustomer.getByID(id, user);
    }
    
    public ArrayList<Customer> getByName(String name, User user) {
        return daCustomer.getByName(name, user);
    }
    
    public ArrayList<Customer> getByIdentity(String identity, User user) {
        return daCustomer.getByIdentity(identity, user);
    }
    
    public ArrayList<Customer> getByOrganzination(String organzination, User user) {
        return daCustomer.getByOrganzination(organzination, user);
    }
    
    public ArrayList<Customer> getByGross(double dGross, User user) {
        return daCustomer.getByGross(dGross, user);
    }
    
    public boolean deleteCustomer(int id) throws Exception{
        return daCustomer.deleteCustomer(id);
    }

    public boolean ennableCustomer(int id) throws Exception{
        return daCustomer.enableCustomer(id);
    }
    public boolean insertCustomer(Customer cus, int userID) throws Exception{
        return daCustomer.insertCustomer(cus,userID);
    }
    
    public boolean updateCustomer(Customer cus)throws Exception{
        return daCustomer.updateCustomer(cus);
    }
    
    public boolean checkIdentity(String identity){
        return daCustomer.checkIdentity(identity);
    }
    
    
     public boolean validateEmail(String email){
        Pattern pattern;
        Matcher matcher;
        String EMAIL_PATTERN ="^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
        pattern = Pattern.compile(EMAIL_PATTERN,Pattern.CASE_INSENSITIVE);
        matcher = pattern.matcher(email);
        if(!matcher.matches())
            JOptionPane.showMessageDialog(null, Localization.getMessage("REG4"),"Error",JOptionPane.WARNING_MESSAGE);
        return matcher.matches();
    }
   
    
}
